module.exports = class Utils{
	static query(e){return document.querySelector(e)}
	static queryAll(e){return document.querySelectorAll(e)}
	static assign(a,b){
		return Object.assign({},a,b)
	}
	static createDOM(tagName,options={}){
		if(options.id){
			let hasCreated = document.getElementById(options.id)
			if(hasCreated)return hasCreated;
		}
		let dom=document.createElement(tagName);
		for(let k in options)dom.setAttribute(k,options[k]);
		return dom;
	}
	static template(str,data){
		if(data instanceof Array)return data.map((d,i)=>{
			return str.replace(/{(.*?)}/g,(a,b)=>{
				return d[b]
			})
		}).join("")
		else return str.replace(/{(.*?)}/g,(a,b)=>{
				return data[b]
			})
	}
	static domRect(dom){
		return dom.getBoundingClientRect()
	}
	static domEach(doms,fn){
		Array.prototype.forEach.call(doms,fn)
	}
	static atan2(y,x){
		let a = Math.atan2(y,x);
		return a<0?(2*Math.PI+a):a;
	}
	static isArray(data){
		return data instanceof Array
	}
	static functional(root,fn,timeout=300){
		clearTimeout(root.timer)
		root.timer=setTimeout(()=>{
			fn()
		},timeout)
	}
}
